﻿using DevExpress.XtraBars;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Ribbon;
using QLKDS.DAL;
using FirstConnectDB;
using System;
using QLKDS.Forms.Report;
using QLKDS.Reports;

namespace QLKDS.Forms
{
    public partial class frmMain : RibbonForm
    {        
        public static WindowManager MainWindowManager;

        private void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(this.rgbiSkins, true);
        }


        public frmMain()
        {
            InitializeComponent();
            InitSkinGallery();

            if (MainWindowManager == null)
            {
                MainWindowManager = new WindowManager();
            }
            
        }

        private void rgbiExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        private void rgbiCategorys_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmCategory();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiBooks_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void rgbiBookUnits_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void rgbiSuppliers_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void rgbiCountries_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void rgbiCustomer_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void navbListCustomers_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.rgbiCustomer_ItemClick(null, null);
        }


        /// <summary>
        /// ////////////////////////
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rgbiImportedGoods_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmImportBooks();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }
        /*
        private void rgbiSale_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmBookDiscount();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }   

         */
        /// <summary>
        /// //////////////
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void navBarControl_Click(object sender, System.EventArgs e)
        {

        }

        private void navbSupplier_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.rgbiSuppliers_ItemClick(null, null);
        }

        private void navbContries_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.rgbiCountries_ItemClick(null, null);
        }

        private void navbBooks_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.rgbiBooks_ItemClick(null, null);
        }

        private void navbBook_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            this.rgbiCategorys_ItemClick(null, null);
        }

        private void rgbiListOfUserGroups_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void rgbiDecentralizedUserGroups_ItemClick(object sender, ItemClickEventArgs e)
        {
        
        }

        private void rgbiListOfUsers_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmUser();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiSale_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void frmMain_Load(object sender, System.EventArgs e)
        {

        }


        private void rgbSupplier_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmSupplier();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbCustomer_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmCustomer();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbAuthors_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmAuthors();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbCategory_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmCategory();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbPublisher_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmPublisher();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbStore_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmStore();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbBook_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmBook();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbStore_Start_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmBookStore();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiChangeProfile_ItemClick(object sender, ItemClickEventArgs e)
        {

            var form = new frmUserChangePassword();

            form.ShowDialog();
        }

        private void rgbiExportedBooks_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmExportBooks();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmAbout form = new FrmAbout();
            form.Show();
        }

        private void rgbiListOrders_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmListImportBook();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiDbConfiguration_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmAddConnection form = new FrmAddConnection();
            form.ShowDialog();
        }

        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmNational();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbReligious_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmReligious();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbDepartmental_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmDepartmental();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbEmployee_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmEmployee();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbLanguage_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmLanguage();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }

        }

     

        private void rgbLevel_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmLevel();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.siTime.Caption = DateTime.Now.ToString();
        }

        private void rgbEmployeeLevel_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmEmployeeLevel();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbLevel_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            var form = new frmLevel();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbEmployeeLanguage_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmEmployeeLanguage();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void barContract_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmContract();

            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiDailyTurnovers_ItemClick(object sender, ItemClickEventArgs e)
        {

            var form = new frmExportDateReport();


            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbAbsent_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmAbsent();


            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbBookReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmBookReport();


            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbSupplierReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            SupplierReportManager manager = new SupplierReportManager();
            rptSupplier rpt = new rptSupplier();
            rpt.DataSource = manager.ListSupplier();
            rpt.ShowPreviewDialog();
        }

        private void rgbCustomerReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            CustomerReportManager manager = new CustomerReportManager();
            rptCustomer rpt = new rptCustomer();
            rpt.DataSource = manager.ListCustomer();
            rpt.ShowPreviewDialog();
        }

        private void rgbEmployeeReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            EmployeeReportManager manager = new EmployeeReportManager();
            rptEmployee rpt = new rptEmployee();
            rpt.DataSource = manager.ListEmployee();
            rpt.ShowPreviewDialog();
        }

        private void rgbiInventory_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmBookInventory();


            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void grbSupplier_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = new frmSupplier();


            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }

        private void rgbiCustomer_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            var form = new frmCustomer();


            if (MainWindowManager.WindowNames.Contains(form.Name) == false)
            {
                MainWindowManager.Windows.Add(form);
                MainWindowManager.WindowNames.Add(form.Name);

                form.MdiParent = this;
                form.Show();
            }
            else
            {
                MainWindowManager.SetFocusSelectedForm(form.Name);
            }
        }




            
    }
}